package com.kiven.quicksort;

public class QuickSort2 {
	private int[] sortNums;
	public int[] getSortNums() {
		return sortNums;
	}
	public void setSortNums(int[] sortNums) {
		this.sortNums = sortNums;
	}
	public void recursionSort(int left,int right) {
		if(left > right) {
			return;
		}
		else {
			int porsition = quickSort(left,right);
			recursionSort(left,porsition-1);
			recursionSort(porsition+1,right);
		}
	}
	public int quickSort(int left, int right) {
		int pivotValue = sortNums[left];
		while(left < right) {
			//从右边开始扫描
			while(left < right && pivotValue < sortNums[right]) {
				right--;
			}
			//从右边扫描到小于pivotValue位置的数值时进行交换
			if(left < right) {
				sortNums[left] = sortNums[right];
				left++;
			}
			//从左边开始扫描
			while(left < right && pivotValue > sortNums[left]) {
				left++;
			}
			if(left < right) {
				sortNums[right] = sortNums[left];
				right--;
			}
		}
		
		sortNums[left] = pivotValue;
		return left;
	}
	
	
}
